#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2015-4-21

@author: abel
'''
import os
import json
from setting_base import env_init
# print(str(os.getenv('TATAUFO_ENV')).upper())

# 初始化
env_init.init()

ENV = str(os.getenv('TATAUFO_ENV')).upper()
# ENV = 'DEV'


# # 根据不同环境而不同的配置
if ENV not in ('PROD', 'FT', 'DEV', 'PRE', 'YUANYONG'):
    raise Exception('System env need to be set~')

config_file = ''
if ENV == 'DEV':
    config_file = 'config-dev.txt'
elif ENV == 'PROD':
    config_file = 'config-prod.txt'

if not config_file:
    raise Exception('Configuration file not found~')

try:
    config_path = os.path.join(os.path.split(os.path.abspath(__file__))[0], config_file)
    config_info = {}
    with open(config_path, 'r') as fs:
        config_info = json.loads(fs.read())
except:
    raise Exception('Configuration file not found~')


def C(item, default=None, strict=True):
    """
    读取配置文件中的配置的参数
    """
    if strict:
        return config_info[item]
    else:
        return config_info.get(item, default)
